﻿using LoveEat.API.Read.Applications.Commands.Goods;
using LoveEat.Domain.Goods;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;

namespace LoveEat.API.Read.Applications.CommandHandlers.Goods
{
    public class GoodsNameQueryCommandHandler : IRequestHandler<GoodsNameQueryCommand, APIResult<List<GoodsNameModel>>>
    {
        private readonly IBaseRespository<GoodsNameModel> nameRep;

        public GoodsNameQueryCommandHandler(IBaseRespository<GoodsNameModel> nameRep)
        {
            this.nameRep = nameRep;
        }

        public Task<APIResult<List<GoodsNameModel>>> Handle(GoodsNameQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<GoodsNameModel>> result=new APIResult<List<GoodsNameModel>>();
            result.Code=APIResultCode.查询成功;
            result.Message=APIResultCode.查询成功.ToString();

            var res=nameRep.GetAll().ToList();
            result.Data=res;


            return Task.FromResult(result);

        }
    }
}
